
import 'package:du_application/provide/GoodsProvider.dart';
import 'package:du_application/provide/setting.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:provide/provide.dart';
import './DetailSwiper.dart';
import './DetailSize.dart';
import './DetailBottomBar.dart';
import './DetailBuyer.dart';
import './DetailRelation.dart';
import './DetailEvaluate.dart';
import './DetailShow.dart';
import './DetailRecommend.dart';
import 'package:flutter_html/flutter_html.dart';


// class GoodsDetailss extends StatelessWidget {
//   const GoodsDetailss({Key key}) : super(key: key);

//   @override
//   Widget build(BuildContext context) {
//      var swiper = [
//     {"image": "https://s2.ax1x.com/2020/01/09/lfJLQS.jpg"},
//     {"image": "https://s2.ax1x.com/2020/01/09/lfJLQS.jpg"}
//   ];
//     ScrollController   _scrollController = ScrollController();
//    double screenHeight = MediaQuery.of(context).size.height;
//    double screenWeight = MediaQuery.of(context).size.width;
//     return  Provide<GoodsProvider>(
//         builder: (context, child,index){
//    return index==null||index.goodsModel==null?Text("111"): Container(
//         child: Scaffold(
//       appBar: AppBar(
//         actions: <Widget>[
//           Padding(
//             child: Icon(Icons.share),
//             padding: EdgeInsets.only(right: 15),
//           )
//         ],
//       ),
//       bottomNavigationBar: DetailBottomBar(),
//       body: ListView(
//         shrinkWrap: true,
//         controller: _scrollController,
//         children: <Widget>[
//           Swipers(swiper: swiper, screenHeight: screenHeight), //首页
//           DetailSize(),
//           DetailRelation(),
//           DetailBuyer(),
//           DetailEvaluate(),
//           DetailShow(),
//           Container(
//             color: Colors.white,
//             child: Html(data: html),
//           ),
//           DetailRecommend(),
//         ],
//       ),
//     ));

//         });
  
//   }
// }
class GoodsDetails extends StatefulWidget {
  GoodsDetails({Key key}) : super(key: key);

  @override
  _GoodsDetailsState createState() => _GoodsDetailsState();
}

class _GoodsDetailsState extends State<GoodsDetails> {

  double screenHeight;
  double screenWeight;
  ScrollController _scrollController;



  @override
  void initState() {
    super.initState();
    
    _scrollController = ScrollController();
  }

  @override
  Widget build(BuildContext context) {
  
    _scrollController = ScrollController();
    screenHeight = MediaQuery.of(context).size.height;
    screenWeight = MediaQuery.of(context).size.width;
   
    return   Provide<GoodsProvider>(
        builder: (context,child,index){
        
   return index==null||index.goodsModel==null?_loadingContainer:
    Container(
        child: Scaffold(
      appBar: AppBar(
        leading:FlatButton(
          onPressed: (){
           Provide.value<SettingProvide>(context).selectBar(0,context);
          },
          child: Icon(Icons.arrow_back),
        ),
        actions: <Widget>[
          Padding(
            child: Icon(Icons.share),
            padding: EdgeInsets.only(right: 15),
          )
        ],
      ),
      bottomNavigationBar: DetailBottomBar(productList:index.goodsModel.data.productList,userHasCollect:index.goodsModel.data.userHasCollect),
      body: ListView(
        shrinkWrap: true,
        controller: _scrollController,
        children: <Widget>[
          Swipers(info:index.goodsModel.data.info, screenHeight: screenHeight), //首页
          DetailSize(attribute:index.goodsModel.data.attribute),
          DetailRelation(forGoods:index.goodsModel.data.forGoods),
          DetailBuyer(),
          DetailEvaluate(comment:index.goodsModel.data.comment,id: index.goodsModel.data.info.id,),
          DetailShow(affairShow:index.goodsModel.data.affairShow??null),
          Container(
            color: Colors.white,
            child: Html(data: index.goodsModel.data.info.detail),
          ),
              index.goodsModel.data.issue!=null&&index.goodsModel.data.issue.length>0?Container(
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
             children:index.goodsModel.data.issue.map((issue){
           return  Container(
             child: Column(
               crossAxisAlignment: CrossAxisAlignment.start,
               children: <Widget>[
                 Container(
                   padding: EdgeInsets.symmetric(horizontal:ScreenUtil().setWidth(20),vertical: ScreenUtil().setWidth(40)),
                   child:Text("${issue.question}",style:TextStyle(
                     fontWeight: FontWeight.bold
                   )),
                 ),
                 Container(
                   padding: EdgeInsets.symmetric(horizontal:ScreenUtil().setWidth(20)),
                   child:Text("${issue.answer}",style:TextStyle(  
                   )),
                 )
               ],
             ),
           );
             }).toList(),
            ),
          ):Container(),
        
          DetailRecommend(goodsList:index.goodsModel.data.goodsList,),
        ],
      ),
    )); 
  });

}
   final _loadingContainer = Container(
      width: ScreenUtil().setHeight(1080),
      height: ScreenUtil().setHeight(1920),
      constraints: BoxConstraints.expand(),
      color: Colors.black,
      child: Center(
        child: Opacity(
          opacity: 0.9,
          child: SpinKitWave(
            color: Colors.white,
            size: 50.0,
          ),
        ),
      ));
}
